//utils/request.ts
//@ts-ignore
import axios, {AxiosInstance, AxiosResponse, InternalAxiosRequestConfig} from "axios";


export let request:AxiosInstance = axios.create({
    //基础路径
    //@ts-ignore
    baseURL: '/api',
    timeout: 5000,//超时时间
})

//请求拦截器
request.interceptors.request.use((config:InternalAxiosRequestConfig) => {
    //config配置对象

    //返回配置对象
    return config;
})

//响应拦截器
request.interceptors.response.use(
    //@ts-ignore
    (response:AxiosResponse<any,any>) => {
        //成果的回调
    },
    (error:Error) => {
        //失败的回调
        return Promise.reject(error)
    }
)

//对外暴露
export default request;